package com;

import com.mybatisplus.MybatisPlusGenteratorCode;
import org.mybatis.generator.api.ShellRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.stream.IntStream;

/**
 * @author zhangyalin@act-telecom.com
 * @date 2019-06-17 17:06
 */
public class MybatisGeneratorCode {

    private static Logger logger = LoggerFactory.getLogger(MybatisPlusGenteratorCode.class);

    public static void main(String[] args) {
        if (args.length > 1) {
            if ("-type".equals(args[0])) {
                String type = args[1];
                String[] argss = new String[args.length - 2];
                IntStream.range(2, args.length).forEach(i -> argss[i - 2] = args[i]);
                if ("1".equals(type)) {
                    //mybatis
                    ShellRunner.main(argss);
                } else if ("2".equals(type)) {
                    //mybatisplus
                    MybatisPlusGenteratorCode.main(argss);
                } else {
                    logger.error("类型参数不匹配！");
                }
            } else {
                logger.error("缺少类型参数\"-type\"");
            }
        } else {
            logger.error("缺少类型参数\"-type\"");
        }
    }
}
